import { RoleHelper } from "./base.role";

// src/roles/harvester.role.ts
export class Harvester implements IRole {
  bodyPart: BodyPartConstant[] = [WORK, CARRY, MOVE];
  readonly role: RoleType = 'harvester';
  readonly priority: number = 1;

  get minCost(): number {
    return 200;
  }

  stateSwitch(creep: Creep) {
    if (creep.memory.working === undefined) {
      creep.memory.working = false;
    }

    if (creep.store.getFreeCapacity() === 0) {
      // 背包满了，切换至储能状态
      creep.memory.working = false;
    } else {
      // 背包没满, 切换至采集状态
      creep.memory.working = true;
    }
  }

  work(creep: Creep) {
    this.stateSwitch(creep);

    if (creep.memory.working) {
      // 采集模式
      RoleHelper.harvestEnergy(creep);
    } else {
      // 存储模式
      RoleHelper.deliverEnergy(creep);
    }
  }
}